<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- creator-valgrind.qdoc -->
  <title>Profiling Function Execution | Qt Creator Manual</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt Creator Manual</a></td><td >Profiling Function Execution</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="index.html">Qt Creator Manual 4.11.1</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
  <link rel="prev" href="creator-analyzer.html" />
  <link rel="next" href="creator-running-valgrind-remotely.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="creator-analyzer.html">Detecting Memory Leaks with Memcheck</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="creator-running-valgrind-remotely.html">Running Valgrind Tools on External Applications</a>
</p><p/>
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#selecting-profiling-options">Selecting Profiling Options</a></li>
<li class="level2"><a href="#enabling-full-cache-simulation">Enabling Full Cache Simulation</a></li>
<li class="level2"><a href="#enabling-branch-prediction-simulation">Enabling Branch Prediction Simulation</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Profiling Function Execution</h1>
<span class="subtitle"></span>
<!-- $$$creator-cache-profiler.html-description -->
<div class="descr"> <a name="details"></a>
<p>You can use the Callgrind tool included in the <a href="http://valgrind.org/info/tools.html">Valgrind tool suite</a> to detect problems that are related to executing functions. In addition, you can load the data files generated by Callgrind into the <a href="https://kcachegrind.github.io/html/Home.html">KCachegrind</a> profile data visualization tool for browsing the performance results.</p>
<p>After you download and install Valgrind tools and KCachegrind, you can use Callgrind and KCachegrind from Qt Creator.</p>
<p><b>Note: </b>You can install and run Callgrind and KCachegrind locally on Linux. You can run Callgrind on a remote Linux machine or device from any development machine.</p><p>To analyze applications:</p>
<ol class="1" type="1"><li>In the <b>Projects</b> mode, select a release build configuration.</li>
<li>Select <b>Debug</b> to open the <b>Debug</b> mode, and then select <b>Callgrind</b> on the toolbar.</li>
<li>Select the <img src="images/qtcreator-analyze-start-button.png" alt="&quot;Start button&quot;" /> button to start the application.</li>
<li>Use the application to analyze it.</li>
<li>Select the <img src="images/stop_small.png" alt="&quot;Stop button&quot;" /> button to view the results of the analysis in the <b>Profile</b> view.</li>
</ol>
<p>Callgrind records the call history of functions that are executed when the application is run. It collects the number of instructions that are executed, their relationship to source lines, the relationships of the caller and callee between functions, and the numbers of such calls. You can also use cache simulation or branch prediction to gather information about the runtime behavior of an application.</p>
<p>Double-click a function to view information about the calling functions in the <b>Callers</b> view and about the called functions in the <b>Callees</b> view.</p>
<p>Since the run-time characteristics of debug and release <a href="creator-glossary.html#glossary-build-config">build configurations</a> differ significantly, analytical findings for one build configuration may not be relevant for the other. Profiling a debug build often finds a major part of the time being spent in low-level code, such as container implementations, while the same code does not show up in the profile of a release build of the same application due to inlining and other optimizations typically done there.</p>
<p>Many recent compilers allow you to build an optimized application with debug information present at the same time. For example, typical options for GCC are: <code>-g -O2</code>. It is advisable to use such a setup for Callgrind profiling.</p>
<p class="centerAlign"><img src="images/qtcreator-valgrind-callgrind.png" alt="&quot;Profile view&quot;" /></p><p>To view the data in KCachegrind, select the <img src="images/kcachegrind.png" alt="" /> (<b>Open Results in KCachegrind</b>) button on the toolbar. Qt Creator launches KCachegrind and loads the data into it for visualization.</p>
<a name="selecting-profiling-options"></a>
<h2 id="selecting-profiling-options">Selecting Profiling Options</h2>
<p>You can specify analyzer settings either globally for all projects or separately for each project in the <a href="creator-run-settings.html">run settings</a> of the project.</p>
<p>To specify settings for Valgrind, select <b>Tools &gt; Options &gt; Analyzer</b>. The <b>Profiling Options</b> group contains Callgrind options.</p>
<p class="centerAlign"><img src="images/qtcreator-valgrind-callgrind-options.png" alt="&quot;Valgrind options&quot;" /></p><p>In the <b>KCachegrind executable</b> field, enter the path to the KCachegrind executable to launch.</p>
<p>In the <b>Result view: Minimum event cost</b> field, limit the amount of results the profiler gives you to increase profiler performance.</p>
<p>You can collect information about the system call times and the number of global bus events of the event type <code>Ge</code> that are executed.</p>
<a name="enabling-full-cache-simulation"></a>
<h3 id="enabling-full-cache-simulation">Enabling Full Cache Simulation</h3>
<p>By default, only instruction read accesses (Ir) are counted. To fully simulate the cache, select the <b>Enable cache simulation</b> check box. This enables the following additional event counters:</p>
<ul>
<li>Cache misses on instruction reads (I1mr/I2mr)</li>
<li>Data read accesses (Dr) and related cache misses (D1mr/D2mr)</li>
<li>Data write accesses (Dw) and related cache misses (D1mw/D2mw)</li>
</ul>
<a name="enabling-branch-prediction-simulation"></a>
<h3 id="enabling-branch-prediction-simulation">Enabling Branch Prediction Simulation</h3>
<p>To enable the following additional event counters, select the <b>Enable branch prediction simulation</b> check box:</p>
<ul>
<li>Number of conditional branches executed and related predictor misses (Bc/Bcm)</li>
<li>Executed indirect jumps and related misses of the jump address predictor (Bi/Bim)</li>
</ul>
</div>
<!-- @@@creator-cache-profiler.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="creator-analyzer.html">Detecting Memory Leaks with Memcheck</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="creator-running-valgrind-remotely.html">Running Valgrind Tools on External Applications</a>
</p>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
